package com.test;

import cn.backpackerxl.entity.Student;
import cn.backpackerxl.service.AdminService;
import cn.backpackerxl.service.StudentService;
import cn.backpackerxl.service.impl.AdminServiceImpl;
import cn.backpackerxl.service.impl.StudentServiceImpl;
import cn.backpackerxl.util.DButils;
import com.alibaba.excel.EasyExcel;
import org.junit.Test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;

import static cn.backpackerxl.util.isEmpty.isEmpty;


/**
 * @author: backpackerxl
 * @create: 2021/12/5
 * @filename: Backpackerxl
 **/
public class Backpackerxl {
    @Test
    public void testStu() {
        StudentService service = new StudentServiceImpl();
        System.out.println(service.findAll(2, 4));
        System.out.println(service.findByName("小", 2, 1));
    }

    @Test
    public void codePasswd() {
//        System.out.println(code("123456"));
        System.out.println("aascv".equalsIgnoreCase("AascvB"));
    }

    @Test
    public void getcontion() throws SQLException {
        Connection connection = DButils.getConnection();
        System.out.println(connection);
    }

    @Test
    public void getHost() {
        Enumeration<NetworkInterface> IpFace = null;
        try {
            IpFace = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            e.printStackTrace();
        }
        List<String> Ipv4 = new ArrayList<>();
        while (IpFace.hasMoreElements()) {
            NetworkInterface networkInterface = IpFace.nextElement();
            try {
                if (!networkInterface.isVirtual() && !networkInterface.isLoopback() && networkInterface.isUp()) {
                    Enumeration<InetAddress> adds = networkInterface.getInetAddresses();
                    while (adds.hasMoreElements()) {
                        InetAddress inetAddress = adds.nextElement();
                        byte[] bs = inetAddress.getAddress();
                        if (bs.length == 4) {
                            Ipv4.add(inetAddress.getHostAddress());
                        }
                    }
                }
            } catch (SocketException e) {
                e.printStackTrace();
            }
        }
    }

    @Test
    public void testExcel(){
        StudentService service = new StudentServiceImpl();
//        HttpServletRequest request = new HttpServletRequestWrapper();
        EasyExcel.write("webapp/download/"+"all.xlsx", Student.class).sheet("学生基本信息表").doWrite(service.downloadStudentInfo());
    }

    @Test
    public void path(){
//        HttpServletRequest request = new HttpServletRequestWrapper();
    }

    @Test
    public void testStudent() {
        Student student = new Student(1, "202013294", "kk", "0", 21, 158, 50, "kkko");
        Student student1 = new Student(2, "202013294", "kk", "0", 21, 158, 50, "kkko");
        System.out.println(student.equals(student1));
    }

    @Test
    public void testFindByEmail() {
        AdminService service = new AdminServiceImpl();
        System.out.println(isEmpty(service.findByEmail("123456@163.com")));
    }
}
